﻿using System.Web.Security;
using System;
using System.Collections;
using DataAccessLogic;
using System.Collections.Generic;
using System.Data.SqlClient;

namespace BusinessLogic
{
    public class AppUser : Table            
    {
        #region Fields
        private Constituent _constituent;        
        private MembershipUser _membershipUser;
        private Guid _membershipUserID;
        #endregion

        #region Methods
        public void Create()
        {
            this._id = AppUserDataAccess.Create(this);
        }

        public void Delete()
        {
            AppUserDataAccess.Delete(this._id);
        }

        public static List<AppUser> GetActive()
        {
            return AppUserDataAccess.GetActive();
        }

        public static List<AppUser> GetAll()
        {
            return AppUserDataAccess.GetAll();
        }

        public static AppUser GetByID(Guid id)
        {
            return AppUserDataAccess.GetByID(id);
        }
        #endregion

        #region Properties
        public Constituent Constituent
        {
            get { return _constituent; }
            set { _constituent = value; }
        }

        public Guid ConstituentID
        {
            get { return _constituent.ID; } 
            set 
            { 
                if(_constituent == null)
                {
                    _constituent = new Constituent();
                    _constituent.ID = value;
                }
                else
                {
                    _constituent.ID = value;
                }
            }           
        }

        public MembershipUser MembershipUser
        {
            get { return _membershipUser; }
            set 
            { 
                _membershipUser = value; 
                _membershipUserID = new Guid(_membershipUser.ProviderUserKey.ToString());
            }            
        }

        public Guid MembershipUserID
        {
            get { return _membershipUserID; }
            set { _membershipUserID = value; }
        }
        
        public Guid ASPNetDbUserID
        {
            get 
            { 
                if(null != _membershipUser)
                {
                    return new Guid(_membershipUser.ProviderUserKey.ToString()); 
                }
                else
                {
                    return _membershipUserID;
                }
            }
        }
        #endregion
    }
}